#ifndef COMMONUI_GFX_RECT_H_
#define COMMONUI_GFX_RECT_H_
#pragma once

#include "../concise-ui.h"
#include "Insets.h"
#include "Point.h"
#include "Size.h"

namespace gfx {

class CONCISEUI_API Rect
{
public:
	Rect(void);
	Rect(const Rect& rect);
	Rect(int width, int height);
	Rect(int x, int y, int width, int height);
	Rect(const gfx::Size& size);
	Rect(const gfx::Point& origin, const gfx::Size& size);
	~Rect(void);

	int X() const { return origin_.X(); }
	void SetX(int x) { origin_.SetX(x); }
	int Y() const { return origin_.Y(); }
	void SetY(int y) { origin_.SetY(y); }

	int Width() const { return size_.Width(); }
	void SetWidth(int width) { size_.SetWidth(width); }
	int Height() const { return size_.Height(); }
	void SetHeight(int height) { size_.SetHeight(height); }

	const Point& Origin() const { return origin_; }
	void SetOrigin(const gfx::Point& origin) { origin_ = origin; }
	void SetOrigin(int x, int y) { origin_.SetPoint(x, y); }
	const Size& Size() const { return size_; }
	void SetSize(const gfx::Size& size) { size_ = size; }

	int Right() const { return X() + Width(); }
	int Bottom() const { return Y() + Height(); }

	void SetRect(int x, int y, int width, int height)
	{
		origin_.SetPoint(x, y);
		size_.SetSize(width, height);
	}

	void Offset(int horizontal, int vertical);
	void Offset(const gfx::Point& point);

	void Inset(int horizontal, int vertical);
	void Inset(int left, int top, int right, int bottom);
	void Inset(const gfx::Insets& insets);

	bool IsEmpty() const { return size_.IsEmpty(); }

	Rect& operator= (const Rect& rhs);
	bool operator == (const Rect& rhs) const;
	bool operator != (const Rect& rhs) const;

	bool Contains(int point_x, int point_y) const;
	bool Contains(const gfx::Point& point) const
	{
		return Contains(point.X(), point.Y());
	}
	bool Contains(const Rect& rect) const;

	bool Intersects(const Rect& rect) const;
	Rect Intersect(const Rect& rect) const;
	Rect Union(const Rect& rect) const;
	Rect Subtract(const Rect& rect) const;
	
	Point CenterPoint() const;

private:
	gfx::Point origin_;
	gfx::Size size_;
};

} // namespace gfx

#endif // COMMONUI_GFX_RECT_H_